define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                pageSize: 25,
                pageList: [25, 50, 'All'],
                extend: {
                    index_url: 'record/payform/index',
                    add_url: '',
                    edit_url: '',
                    del_url: 'record/payform/del',
                    multi_url: 'record/payform/multi',
                    table: 'hey_pay_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'out_request_no', title: __('Order_sn')},
                        // {field: 'pay_sn', title: __('Pay_sn')},
                        {field: 'pay_scope', title: __('Pay_scope')},
                        {field: 'buyer_status', title: __('Buyer_status'), searchList: {"unchecked":__('Buyer_status unchecked'),"same":__('Buyer_status same'),"different":__('Buyer_status different')}, formatter: Table.api.formatter.status},
                        {field: 'buyer_name', title: __('Buyer_name')},
                        // {field: 'buyer_mobile', title: __('Buyer_mobile')},
                        {field: 'order_fee', title: __('Order_fee'), operate:'BETWEEN'},
                        {field: 'record_time', title: __('Record_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'response_code', title: __('Response_code')},
                        {field: 'response_msg', title: __('Response_msg')},
                        {field: 'record_status', title: __('Record_status'), searchList: {"undeclared":__('Record_status undeclared'),"submitted":__('Record_status submitted'),"processing":__('Record_status processing'),"success":__('Record_status success'),"failure":__('Record_status failure'),"except":__('Record_status except')}, formatter: Table.api.formatter.status},
                        // {field: 'out_request_no', title: __('Out_request_no')},
                        {field: 'verify_depart', title: __('Verify_depart')},
                        {field: 'depart_trade_no', title: __('Depart_trade_no')},
                        {field: 'admin.nickname', title: __('Admin.nickname')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                            {
                                name: 'detail',
                                title: __('详细信息'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                url: 'record/payform/detail',
                                // callback: function (data) {
                                //     Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                // },
                                hidden:function(row){
                                    return false; 
                                }
                            },{
                                name: 'customs_query',
                                title: __('报关查询'),
                                text: '',
                                classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                confirm: '确认发送',
                                extend: ' data-toggle="tooltip"',
                                url: '/api/hey_pay_customs/customs_query?record_id={id}',
                                hidden:function(row){
                                    if(row.out_request_no){ 
                                        return false; 
                                    }else{
                                        return true;
                                    }
                                }
                            },
                        ]}
                    ]
                ],
                onDblClickRow: function (row) { // 重写双击事件
                    Backend.api.open('record/payform/detail/ids/'+row.ids, __('详细信息'), {});
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});